package com.yonyou.cyxdms.sysAuth.service.controller.broker;

import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import com.yonyou.cyxdms.sysAuth.service.dto.broker.*;
import com.yonyou.cyxdms.sysAuth.service.service.broker.BrokerService;
import com.yonyou.cyxdms.sysAuth.service.vo.user.BrokerDealerInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * DMS经纪人信息处理
 *
 * @author zhangsx
 * @since 2018-09-17
 */
@RestController
@RequestMapping("/api/broker/")
@Api(value = "DMS经纪人信息处理")
public class BrokerController extends BaseController {

    @Autowired
    public BrokerService ibrokerposervice;
    private Logger logger = LoggerFactory.getLogger(BrokerController.class);

    /**
     * 查看个人名片中的信息，查看信息详情
     *
     * @param
     * @return com.yonyou.cyx.broker.service.model.dto.BrokerDTO
     * @author renw
     * @since 2018/12/4
     */
    @GetMapping(value = "/getBrokerCard", produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "查询个人名片中的信息", notes = "详细信息")
    public BrokerCardDTO getBrokerCard(@RequestParam("uid") Long uid) {
        logger.debug("获取名片：{}", uid);
        if (uid == null) {
            uid = ApplicationContextHelper.getBeanByType(LoginInfoDto.class).getUserId();
        }
        //通过获取dealer微服务里面的dealer_id找到经销商信息
        return ibrokerposervice.getBrokerCard(uid);
    }

    // fixme 此处为修改名片的接口，直接在DMS里面实现，请移步：LonginController -> updateEmpInfo
//    @PostMapping(value = "/updateBusiness")
//    @ApiOperation("名片更新接口")
//    public BrokerDTO updateBusiness(@RequestBody BrokerDTO brokerDTO) {
//        return iBrokerPOService.updateBusiness(brokerDTO);
//    }

    @PostMapping(value = "/getBrokers")
    @ApiOperation(value = "获取顾问基本信息", notes = "暂且用于小程序列表获取顾问信息")
    public List<BrokerInfoDTO> queryBrokerInfoByUids(@RequestBody List<String> uids) {
        return ibrokerposervice.getBrokerByUserTokens(uids);
    }


    @GetMapping(value = "/queryBrokerInfoByUidsAndAppId")
    @ApiOperation(value = "获取顾问基本信息", notes = "暂且用于小程序列表获取顾问信息")
    public List<BrokerInfoDTO> queryBrokerInfoByUidsAndAppId(@RequestParam("uids") List<String> uids, @RequestParam("appId") String appId) {
        return ibrokerposervice.getBrokerByUidsAndAppId(uids, appId);
    }

    /**
     * 模糊查询经纪人信息
     *
     * @author dengqiang
     * @since 2019/2/19
     */
    @GetMapping("/queryBrokerInfoByDealerId")
    @ApiOperation(notes = "查询所有顾问信息", value = "查询所有顾问信息")
    public List<BrokerByDlerIdDTO> queryBrokerInfoByDealerId(@RequestParam("dealerId") String dealerId) {
        return ibrokerposervice.queryBrokerInfoByDealerId(dealerId);
    }


    /**
     * 模糊查询经纪人信息
     *
     * @author dengqiang
     * @since 2019/2/19
     */
    @GetMapping("/queryBrokerInfoByDealerIdAndAppId")
    @ApiOperation(notes = "查询所有顾问信息", value = "查询所有顾问信息")
    public List<BrokerByDlerIdDTO> queryBrokerInfoByDealerIdAndAppId(@RequestParam("dealerId") String dealerId, @RequestParam("appId") String appId) {
        return ibrokerposervice.queryBrokerInfoByDealerCodeAndAppId(dealerId, appId);
    }

    /**
     * 模糊查询经纪人信息
     *
     * @author dengqiang
     * @since 2019/2/19
     */
    @GetMapping("/getBrokerInfo")
    @Deprecated
    @ApiOperation(notes = "经纪人信息", value = "经纪人信息")
    public List<BrokerCardVo> queryBrokerInfo(@RequestParam("appId") String appId, @RequestParam("forWord") String forWord) {
        return ibrokerposervice.queryBrokerInfo(appId, forWord);
    }

    /**
     * 获取经纪人详情根据DMS系统的UserId
     *
     * @param dmsId dmsId
     * @return com.yonyou.cyx.broker.service.model.dto.BrokerDTO
     * @author renwd
     * @since 2018/9/19
     */
    @GetMapping("/brokerInfoByExtId/{dmsId}")
    @ApiOperation(value = "根据DMS系统的ID获取经纪人信息", notes = "经纪人的ID就是整个CCSS系统通用的ID")
    public BrokerDTO brokerInfoByExtId(@PathVariable(value = "dmsId") String dmsId) {
        return ibrokerposervice.getByDmsId(dmsId);
    }

    /**
     * 获取经纪人详情根据DMS系统的UserId
     *
     * @param userCode userCode
     * @param appId    appId
     * @return com.yonyou.cyx.broker.service.model.dto.BrokerDTO
     * @author renwd
     * @since 2018/9/19
     */
    @GetMapping("/brokerInfoByUserCodeAndAppId")
    @ApiOperation(value = "根据DMS系统的ID获取经纪人信息", notes = "经纪人的ID就是整个CCSS系统通用的ID")
    public BrokerDTO brokerInfoByUserCodeAndAppId(@RequestParam("userCode") String userCode, @RequestParam("appId") String appId) {
        return ibrokerposervice.getByUserCodeAndAppId(userCode, appId);
    }


    /**
     * 微信获取销售顾问信息
     *
     * @param brokerId 经纪人Id
     * @return java.util.Map
     * @author renwd
     * @since 2018/9/19
     */
    @GetMapping(value = "/findBrokerInfo", produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "微信获取销售顾问信息")
    public Map<String, Object> findBrokerInfo(@RequestParam Long brokerId) {
        return ibrokerposervice.findBrokerInfo(brokerId);
    }

    /**
     * 获取顾问信息
     * @author lijun
     */
    @GetMapping(value = "/selectBrokerInfo", produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "获取顾问信息", notes = "获取顾问信息")
    public List<BrokerCardVo> getBrokerInfo(@RequestParam("appId") String appId,
                                       @RequestParam(value = "userIds", required = false) List<String> userIds,
                                       @RequestParam(value = "userCodes", required = false) List<String> userCodes) {
        return ibrokerposervice.getBrokerInfo(appId, userIds, userCodes);
    }

    /**
     * 获取顾问信息
     *
     * @author houkh
     */
    @GetMapping(value = "/brokerInfo", produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "获取顾问信息", notes = "获取顾问信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "租户ID", name = "appId", paramType = "String", type = "header"),
            @ApiImplicitParam(value = "用户ID", name = "userId", paramType = "String", type = "header"),
            @ApiImplicitParam(value = "用户名称", name = "userName", paramType = "String", type = "header"),
            @ApiImplicitParam(value = "经销商代码", name = "ownerCode", paramType = "String", type = "header"),
            @ApiImplicitParam(value = "用户职位ID", name = "userOrgId", paramType = "String", type = "header")
    })
    public BrokerDealerInfoVO brokerInfo(@RequestParam(value = "uid", required = false) String userId,
                                         @RequestHeader(value = "appId") String appId) {
        return ibrokerposervice.brokerInfo(userId, appId);
    }

    /**
     * 获取顾问信息
     *
     * @author houkh
     */
    @GetMapping(value = "/brokerInfoApp", produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "获取顾问信息", notes = "获取顾问信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "租户ID", name = "appId", paramType = "String", type = "header"),
            @ApiImplicitParam(value = "用户ID", name = "userId", paramType = "String", type = "header"),
            @ApiImplicitParam(value = "用户名称", name = "userName", paramType = "String", type = "header"),
            @ApiImplicitParam(value = "经销商代码", name = "ownerCode", paramType = "String", type = "header"),
            @ApiImplicitParam(value = "用户职位ID", name = "userOrgId", paramType = "String", type = "header")
    })
    public BrokerDealerInfoVO brokerInfoApp(@RequestParam(value = "userId", required = false) String userId,
                                            @RequestHeader(value = "appId") String appId) {
        return ibrokerposervice.brokerInfoApp(userId, appId);
    }


}